import {BasicColumn} from '/@/components/Table';
import {FormSchema} from '/@/components/Table';
import { rules} from '/@/utils/helper/validator';
import { render } from '/@/utils/common/renderUtils';
import { h } from 'vue';
import { getFileAccessHttpUrl } from '/@/utils/common/compUtils';
//列表数据
export const columns: BasicColumn[] = [
  {
    title: '医院ID',
    align: "center",
    width: 220,
    dataIndex: 'hospitalid'
  },
  {
    title: '医院名字',
    align: "center",
    width: 300,
    dataIndex: 'hospitalname'
  },
  {
    title: '项目组ID',
    align: "center",
    width: 220,
    dataIndex: 'projectid'
  },
  {
    title: '项目组名字',
    align: "center",
    dataIndex: 'projectname'
  },
  {
    title: '标题',
    align: "center",
    width: 220,
    dataIndex: 'title'
  },
  {
    title: '内容',
    align: "center",
    dataIndex: 'contain',
    width: 600,
  },
  {
    title: '价格',
    align: "center",
    dataIndex: 'price'
  },
  {
    title: '图片地址',
    align: "center",
    dataIndex: 'pic',
    customRender: render.renderImage,
  },
  {
    title: '视频地址',
    align: "center",
    dataIndex: 'video',
    customRender: ({ text }) => {
      if (!text) return '';
      const url = text.split(',')[0];
      const fileName = url.substring(url.lastIndexOf('/') + 1);
      return h('a', { 
        href: getFileAccessHttpUrl(url), 
        target: '_blank',
        style: { color: '#1890ff' }
      }, fileName || '下载文件');
    },
  },
];

//查询数据
export const searchFormSchema: FormSchema[] = [
  {
    label: "医院名字",
    field: 'hospitalname',
    component: 'Input',
    //colProps: {span: 6},
  },
  {
    label: "项目组名字",
    field: 'projectname',
    component: 'Input',
    //colProps: {span: 6},
  },
  {
    label: "标题",
    field: 'title',
    component: 'Input',
    //colProps: {span: 6},
  },
];

//表单数据
export const formSchema: FormSchema[] = [
  {
    label: '医院ID',
    field: 'hospitalid',
    component: 'Input',
  },
  {
    label: '医院名字',
    field: 'hospitalname',
    component: 'Input',
  },
  {
    label: '项目组ID',
    field: 'projectid',
    component: 'Input',
  },
  {
    label: '项目组名字',
    field: 'projectname',
    component: 'Input',
  },
  {
    label: '标题',
    field: 'title',
    component: 'Input',
  },
  {
    label: '内容',
    field: 'contain',
    component: 'JEditor',
  },
  {
    label: '价格',
    field: 'price',
    component: 'InputNumber',
  },
  {
    label: '图片地址',
    field: 'pic',
    component: 'JImageUpload',
    componentProps: {
      fileMax: 1,
    },
  },
  {
    label: '视频地址',
    field: 'video',
    component: 'JUpload',
    componentProps: {
      maxCount: 1,
    },
  },
	// TODO 主键隐藏字段，目前写死为ID
  {
    label: '',
    field: 'id',
    component: 'Input',
    show: false,
  },
];

// 高级查询数据
export const superQuerySchema = {
  hospitalid: {title: '医院ID',order: 0,view: 'text', type: 'string',},
  hospitalname: {title: '医院名字',order: 1,view: 'text', type: 'string',},
  projectid: {title: '项目组ID',order: 2,view: 'text', type: 'string',},
  projectname: {title: '项目组名字',order: 3,view: 'text', type: 'string',},
  title: {title: '标题',order: 4,view: 'text', type: 'string',},
  contain: {title: '内容',order: 5,view: 'umeditor', type: 'string',},
  price: {title: '价格',order: 6,view: 'number', type: 'number',},
  pic: {title: '图片地址',order: 7,view: 'image', type: 'string',},
  video: {title: '视频地址',order: 8,view: 'file', type: 'string',},
};
